from fogmini import global_objects
from fogmini.api.fogbugz import FogBugz
from fogmini.utils import get_config_value, set_config_value

def login():
    base_url = get_config_value("base_url", "").toString()
    if base_url == "":
        global_objects.tray.showMessage("Settings Required", "Left click on the FogBugz icon to enter your login details.")
    else:
        username = get_config_value("username", "").toString()
        password = get_config_value("password", "").toString()

        global_objects.fb = FogBugz(unicode(base_url))
        global_objects.fb.logon(username, password)

        global_objects.app.login_successful.emit()
